package com.practice.tomcat.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Configuration;

/**
 * @Description : 内嵌tomcat信息
 * @Author : guxuemin
 * @Version : V1.0.0
 * @Date : 2021/9/12 15:42
 */
@Configuration
@Slf4j
public class TomcatCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
    @Override
    public void customize(TomcatServletWebServerFactory factory) {
        factory.addConnectorCustomizers(connector -> {
            AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) connector.getProtocolHandler();

            log.info("####################################################################################");
            log.info("#");
            log.info("# TomcatCustomizer");
            log.info("#");
            log.info("# accept-count {}", protocol.getAcceptCount());
            log.info("# max connections: {}", protocol.getMaxConnections());
            log.info("# max swallow size: {} byte", protocol.getMaxSwallowSize());
            log.info("# max threads: {}", protocol.getMaxThreads());
            log.info("# min spare threads: {}", protocol.getMinSpareThreads());
            log.info("# connection timeout: {} ms", protocol.getConnectionTimeout());
            log.info("# keepalive timeout: {} ms", protocol.getKeepAliveTimeout());
            log.info("# max header count: {}", protocol.getMaxHeaderCount());
            log.info("# max parameter count: {}", connector.getMaxParameterCount());
            log.info("# max post size: {} byte", connector.getMaxPostSize());
            log.info("# acceptor thread count:{}", protocol.getAcceptorThreadCount());
            log.info("# max http header size: {} byte", protocol.getMaxHttpHeaderSize());
            log.info("# protocol {}", connector.getProtocol());
            log.info("#");
            log.info("####################################################################################");
        });
    }
}
